//Large Ammo Cache script
// Modified by Spam_One with low proba, since a new ammo cache mission spawns in cities, with hordes (better for gameplay to push players there)

//------------------------------------------- probability for mission begins

_proba = random 100;
if (_proba < 25) then {
	diag_log " Missions 1 launched";
	//------------------------------------------- mission script if proba > 25
	
	private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker","_checking","_people","_hillpos"];
	
	sleep 300;
	
	[player,nil,rSIDECHAT,STR_MISSION_TEXT_1] call RE;
	[nil,nil,rHINT,STR_MISSION_TEXT_1] call RE;
	private ["_rad","_cnps","_hills","_hillcount","_hillnum","_hill","_marker"];
	
	_rad=20000;
	_cnps = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
	_hills = nearestLocations [_cnps, ["FlatArea"], _rad];
	_hillcount = count _hills;
	_hillnum = floor (random _hillcount);
	_hill = _hills select _hillnum;
	_hillpos = getpos _hill;
	
	_marker = "";
	if (CVG_sideMarkers == 0) then {
		_marker_name = STR_MISSION_MARKER_1 + str (random 50);
		_marker = createMarker [_marker_name,_hillpos];
		_marker setMarkerType "mil_destroy";
		_marker setMarkerColor "ColorYellow";
		_marker setMarkerText STR_MISSION_MARKER_1;
		_marker setMarkerSize [1,1];
	};
	
	if (CVG_sideMarkers == 1) then {
		_hillpos = [(_hillpos select 0) + random 100, (_hillpos select 1) + random 100,0];
		_marker_name = STR_MISSION_MARKER_1 + str (random 50);
		_marker = createMarker [_marker_name,_hillpos];
		_marker setMarkerShape "ellipse";
		_marker setMarkerBrush "DiagGrid";
		_marker setMarkerColor "ColorYellow";
		_marker setMarkerText STR_MISSION_MARKER_1;
		_marker setMarkerSize [200,200];
	};
	
	missionActive = true;
	missionVars = [STR_MISSION_MARKER_1,_hillpos];
	publicVariable "missionActive";
	publicVariable "missionVars";
	
	BOX = createVehicle ["USVehicleBox",[(getpos _hill select 0) + (floor random 40), (getpos _hill select 1) + (floor random 40),0],[], 0, "NONE"];
	BOX setVehicleVarName "USVehicleBox";
	[BOX] execVM "craigs_scripts\fillBoxes.sqf";
	
	_checking = 1;
	while {_checking == 1} do {
		_people =  nearestObjects [[getpos BOX select 0, getpos BOX select 1,0],["Man"],50];
		if ((count _people) > 0) then {_checking = 0};
		sleep 1;
	};
	
	
	[player,nil,rSIDECHAT,"The Gear Cache has been found, nice work, enjoy the spoils."] call RE;
	[nil,nil,rHINT,"The Gear Cache has been found, nice work, enjoy the spoils."] call RE;
	deleteMarker _marker;
	missionActive = false;
	publicVariable "missionActive";
	
	// hordes // Spam_One -------------------------------------------------------------------------
	
	// putting a unit which we can rotate for finding a safe pos and randomize where hordes come from
	
	_safePos = [BOX, 50, 50 , 75] call WF_FNCT_getRandomSafePos;
	
	// first Horde --------------------------------------------------------------------------------
	
	trigger = createTrigger ["EmptyDetector", _safePos];
	trigger setTriggerArea [10,10,0,false];
	[trigger,30,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
	//hint "first horde spawned";
	sleep 20;
	
	// second Horde -------------------------------------------------------------------------------
	
	_safePos = [BOX, 50, 50 , 75] call WF_FNCT_getRandomSafePos;
	
	trigger2 = createTrigger ["EmptyDetector", _safePos];
	trigger2 setTriggerArea [10,10,0,false];
	[trigger2,18,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
	//hint "second horde spawned";
	sleep 20;
	
	// End of hordes ------------------------------------------------------------------------------
	
	
	SM1 = 1;
	[0] execVM "sideMissions\SMfinder.sqf";
}

//---------------------------------------- else if _proba < 25

else {
	[] execVM "sideMissions\SMfinder.sqf";
};

//--------------------------------------- find another mission